<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">发送消息</button>
    <script src="./socket.io.min.js"></script>
    <script>
      // 连接上web socket服务器
      const socket = io("ws://localhost:3000");

      document.getElementById("btn").onclick = () => {
        // 客户端向服务器发送消息
        socket.emit("msg", "hello ws");
      };

      // 客户端接受服务器的消息
      socket.on("hello", (content) => {
        console.log(content);
      });
    </script>
  </body>
</html>
